let isHandSome: Boolean = false
isHandSome = true

let isNumber: number = 1
isNumber = 3


let realName: string = 'str'
realName = `A${realName}`
console.log('>>>realName', realName)

// undefined null
let u:undefined = undefined
let n:null = null
console.log('>>>u', u)

function divide(params: any) {
    return params / 2
}
function divide2(params: unknown) {
    return params as number / 2
}
console.log('>>>divide', divide('466t'), divide2(466))

function welcome() :void {
    console.log('void')
}
welcome()

function toError(msg: string):never {
    throw new Error(msg)
}
// toError('错误')

let numArr: number[] = [1,2]
numArr.push(4)

let tuple:[number, string] = [1,'2']
let tuple2:[object] = [{a:1,b:2}]
tuple2.push({c:33})
console.log('>>>tuple2', tuple2)

function add(x:number, y:number, z?:number):number {
    return x + y
}
function add2([x,y,z]:[number,number,number]):number {
    return x + y
}
console.log('>>>add', add(1,2))

// interface Person {
//     readonly name: string,
//     age?: number
// }
// const p1: Person = {
//     name: 'liming',
//     age: 18
// }
// p1.age = 292
// console.log('>>>person', p1)

interface likeArray {
    [propName: number]:string
}
const arr: likeArray = ['33', '393', '23920', '233']
console.log('>>>likeArray', arr)

interface functionWithProps {
    (x:number): number,
    fnName: string
}
const fnWithProps: functionWithProps = (x) => {
    return x
}
fnWithProps.fnName = 'hello world!'
console.log('>>>fnWithProps', fnWithProps(3))

class Person {
    name: string
    constructor(name: string) {
        this.name = name
    }
    speak() {
        console.log(`${this.name} is speaking`)
    }
}

const p1 = new Person('lin')      // 新建实例  

p1.name                           // 访问属性和方法
p1.speak()

class Student extends Person {
    grade: number
    constructor(name: string, grade: number) {
        super(name)
        this.grade = grade
    }
    study() {
        console.log(`${this.name} needs study ${this.grade}`)
    }
}
const student1 = new Student('liming', 100)
student1.study()